Bipolar field


In [1]:
from konfoo import Index, Byteorder, Bipolar, Bipolar2, Bipolar4

Item

Item type of the field class.


In [2]:
Bipolar.item_type


Out[2]:
ItemClass.Bipolar = 51

Checks if the field class is a bit field.


In [3]:
Bipolar.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
Bipolar.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
Bipolar.is_decimal()


Out[5]:
True

Checks if the field class is a floating point number field.


In [6]:
Bipolar.is_float()


Out[6]:
False

Checks if the field class is a pointer field.


In [7]:
Bipolar.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
Bipolar.is_stream()


Out[8]:
False

Checks if the field class is a string field.


In [9]:
Bipolar.is_string()


Out[9]:
False

Field


In [10]:
bipolar = Bipolar(bits_integer=2, bit_size=16, align_to=None, byte_order='auto')

In [11]:
bipolar = Bipolar(2, 16)

Field view


In [12]:
bipolar


Out[12]:
Bipolar(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=2, bit_offset=0), bit_size=16, value=0.0)

In [13]:
str(bipolar)


Out[13]:
'Bipolar2.16(Index(byte=0, bit=0, address=0, base_address=0, update=False), Alignment(byte_size=2, bit_offset=0), 16, 0.0)'

In [14]:
repr(bipolar)


Out[14]:
'Bipolar(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=2, bit_offset=0), bit_size=16, value=0.0)'

Field name


In [15]:
bipolar.name


Out[15]:
'Bipolar2.16'

Field index


In [16]:
bipolar.index


Out[16]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Byte index of the field within the byte stream.


In [17]:
bipolar.index.byte


Out[17]:
0

Bit offset relative to the byte index of the field within the byte stream.


In [18]:
bipolar.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
bipolar.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
bipolar.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


In [21]:
bipolar.index_field(index=Index())


Out[21]:
Index(byte=2, bit=0, address=2, base_address=0, update=False)

Field alignment


In [22]:
bipolar.alignment


Out[22]:
Alignment(byte_size=2, bit_offset=0)

Byte size of the field group which the field is aligned to.


In [23]:
bipolar.alignment.byte_size


Out[23]:
2

Bit offset of the field within its aligned field group.


In [24]:
bipolar.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
bipolar.bit_size


Out[25]:
16

Field byte order


In [26]:
bipolar.byte_order


Out[26]:
Byteorder.auto = 'auto'

In [27]:
bipolar.byte_order.value


Out[27]:
'auto'

In [28]:
bipolar.byte_order.name


Out[28]:
'auto'

In [29]:
bipolar.byte_order = 'auto'

In [30]:
bipolar.byte_order = Byteorder.auto

Field value

Checks if the decimal field is signed or unsigned.


In [31]:
bipolar.signed


Out[31]:
False

Maximal decimal field value.


In [32]:
bipolar.max()


Out[32]:
65535

Minimal decimal field value.


In [33]:
bipolar.min()


Out[33]:
0

Returns the bipolar field value as a floating point number.


In [34]:
bipolar.value


Out[34]:
0.0

Returns the decimal field value aligned to its field group as a number of bytes.


In [35]:
bytes(bipolar)


Out[35]:
b'\x00\x00'

In [36]:
bytes(bipolar).hex()


Out[36]:
'0000'

Returns the decimal field value as an integer number.


In [37]:
int(bipolar)


Out[37]:
0

Returns the decimal field value as an floating point number.


In [38]:
float(bipolar)


Out[38]:
0.0

Returns the decimal field value as a lowercase hexadecimal string prefixed with 0x.


In [39]:
hex(bipolar)


Out[39]:
'0x0'

Returns the decimal field value as a binary string prefixed with 0b.


In [40]:
bin(bipolar)


Out[40]:
'0b0'

Returns the decimal field value as an octal string prefixed with 0o.


In [41]:
oct(bipolar)


Out[41]:
'0o0'

Returns the decimal field value as a boolean value.


In [42]:
bool(bipolar)


Out[42]:
False

Returns the decimal field value as a signed integer number.


In [43]:
bipolar.as_signed()


Out[43]:
0

Returns the decimal field value as an unsigned integer number.


In [44]:
bipolar.as_unsigned()


Out[44]:
0

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [45]:
bipolar.describe()


Out[45]:
OrderedDict([('address', 0),
             ('alignment', [2, 0]),
             ('class', 'Bipolar2.16'),
             ('index', [0, 0]),
             ('max', 65535),
             ('min', 0),
             ('name', 'Bipolar2.16'),
             ('order', 'auto'),
             ('signed', True),
             ('size', 16),
             ('type', 'Field'),
             ('value', 0.0)])

Deserialize


In [46]:
bipolar.deserialize(bytes.fromhex('0100'), byte_order='little')


Out[46]:
Index(byte=2, bit=0, address=2, base_address=0, update=False)

In [47]:
bipolar.value


Out[47]:
0.006103515625

In [48]:
bytes(bipolar)


Out[48]:
b'\x01\x00'

In [49]:
bytes(bipolar).hex()


Out[49]:
'0100'

In [50]:
int(bipolar)


Out[50]:
1

In [51]:
float(bipolar)


Out[51]:
0.006103515625

In [52]:
hex(bipolar)


Out[52]:
'0x1'

In [53]:
bin(bipolar)


Out[53]:
'0b1'

In [54]:
oct(bipolar)


Out[54]:
'0o1'

In [55]:
bool(bipolar)


Out[55]:
True

Serialize


In [56]:
buffer = bytearray()

In [57]:
bipolar.value = -1

In [58]:
bipolar.value = -1.0

In [59]:
bipolar.value = -0x1

In [60]:
bipolar.value = -0b1

In [61]:
bipolar.value = -0o1

In [62]:
bipolar.value = True

In [63]:
bipolar.value = -1.0

In [64]:
bipolar.serialize(buffer, byte_order='little')


Out[64]:
Index(byte=2, bit=0, address=2, base_address=0, update=False)

In [65]:
buffer.hex()


Out[65]:
'a380'

In [66]:
bytes(bipolar).hex()


Out[66]:
'a380'

In [ ]: